package com.example.product2.service;

import com.example.product2.entity.Stu;
import com.example.product2.repository.StuRepository;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class StuService {
    @Autowired
    private StuRepository repository;
    @Autowired
    private RestTemplate restTemplate;

    @GlobalTransactional(rollbackFor = Exception.class)
    public void add(String name,Integer stuId,Integer mm){
        Stu stu=new Stu();
        stu.setName(name);
        Stu save = repository.save(stu);
        System.out.println(save);
        Object object = restTemplate.getForObject("http://product1/add?stuId=" + stuId + "&mm=" + mm, Object.class);
        System.out.println(object);
    }
}
